<!DOCTYPE html>
<#assign ctx=Session.basePath>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>发布消息</title>
    <link href="${ctx}/easyui/themes/bootstrap/easyui.css" rel="stylesheet"/>
    <link href="${ctx}/easyui/themes/icon.css" rel="stylesheet"/>
    <script src="${ctx}/js/jquery-1.12.2.min.js"></script>
    <script src="${ctx}/lib/jquery.form.js"></script>
    <script src="${ctx}/easyui/jquery.easyui.min.js"></script>
    <script src="${ctx}/easyui/locale/easyui-lang-zh_CN.js"></script>
    <script src="${ctx}/pagination/js/layer/layer.js"></script>

    <script>
        var ships = '<#if ships??>${ships}<#else></#if>';
        var company =  '<#if company??>${company}<#else></#if>';
    </script>
    <style>
        body {
            background-color: #fff;
        }
    </style>
</head>
<body>

<#--<div id="tb" style="padding:5px;height:auto">-->
    <#--<div>-->
        <#--开始时间: <input id="stime" placeholder="开始时间" class="easyui-datebox" style="width:120px">-->
        <#--结束时间: <input id="etime" placeholder="结束时间" class="easyui-datebox" style="width:120px">-->
        <#--标题:<input id="title" placeholder="标题" class="textbox-text validatebox-text textbox-prompt" style="120px">-->
        <#--船舶:<input id="shipName" placeholder="船舶" class="textbox-text validatebox-text textbox-prompt" style="120px">-->
        <#--<a href="#" class="easyui-linkbutton btn-search" iconCls="icon-search" style="width: 80px;">查找</a>-->
        <#--<a href="#" class="easyui-linkbutton btn-add" plain="true" icon="icon-add">新增</a>-->
    <#--</div>-->
<#--</div>-->

<#--<table id="dg"-->
       <#--data-options="rownumbers:true,singleSelect:true,pagination:true,url:'${ctx}/manage/message/ajax/list',method:'post',toolbar:'#tb'">-->
    <#--<thead>-->
    <#--<tr>-->
        <#--<th data-options="field:'shipName',width:150">船舶</th>-->
        <#--<th data-options="field:'title',width:130">标题</th>-->
        <#--<th data-options="field:'sendtime',width:120">发送时间</th>-->
        <#--<th data-options="field:'msgauthor',width:140">发送人</th>-->
        <#--<th data-options="field:'msgstate',width:140">消息状态</th>-->
        <#--<th data-options="field:'msgcontent',width:190">内容</th>-->
    <#--</tr>-->
    <#--</thead>-->
<#--</table>-->
<script type="text/javascript">
    $(function () {
        var pager = $('#dg').datagrid({
            fitColumns: true,
            fit: true,
            loadFilter: function (data) {
                if (data != null && data.rows != null) {
                    for (var i = 0; i < data.rows.length; i++) {
                        var record = data.rows[i];
                        record.shipName = record.shipInfo.shipName;
                        var msgstate = record.msgstate;
                        if(msgstate){
                            if(msgstate == "0"){
                                msgstate = "草稿";
                            }else if(msgstate == "1"){
                                msgstate = "发送";
                            }
                        }
                        record.msgstate = msgstate;
                    }
                }
                return data;
            }
        });	// get the pager of datagrid

        $(".btn-search").click(function () {
            $('#dg').datagrid("load", {
                stime: $("#stime").datebox('getValue'),
                etime: $("#etime").datebox('getValue'),
                title: $("#title").val(),
                shipName: $("#shipName").val()
            })
        })

        $(".btn-add").click(function () {
            $("#contentForm").form("clear");
            $("#window").window('open');
        })

        if(ships != null && ships != ""){
            $("#window").window('open');
            $("#contentForm").form("load",{
                shipid:ships.split(",")
            });
        }
    })

    function onSubmit() {
        $('#contentForm').form('submit',{
            onSubmit:function(){
                return $(this).form('enableValidation').form('validate');
            }
        });
    }

    function submitForm() {
        var valid = $("#contentForm").form('enableValidation').form('validate');
        if(valid){
            $("#contentForm").ajaxSubmit(function (response) {
                if(response.success){
//                    $("#window").window('close');
//                    $('#dg').datagrid().load()
//                    window.parent.layer.closeAll();
                         window.parent.layer.close(window.parent.sendLayer);
                }else{
                    layer.msg("保存失败");
                }
            })
        }
    }
</script>

<#--<div id="window" class="easyui-window" title="发送消息" data-options="modal:false,closed:true"-->
     <#--style="width:400px;height:320px;padding:10px;">-->
    <div class="easyui-layout" data-options="fit:true">
        <div data-options="region:'center'">
            <form id="contentForm" class="form-horizontal" method="post" action="/manage/message/update" style="padding: 20px;"
                  data-parsley-validate="" novalidate="novalidate">
                <table cellpadding="5">
                    <tr>
                        <td style="width: 100px">
                            标题<span class="text-danger">*</span>
                        </td>
                        <td style="width: 200px;">
                            <input type="text" data-options="required:true" class="form-control easyui-textbox" name="title" placeholder="标题"
                                   value="" aria-required="true">
                        </td>
                    </tr>

                    <tr>
                        <td>
                            <label class="col-sm-4 control-label">消息内容<span class="text-danger">*</span></label>
                        </td>
                        <td>
                            <input type="text" data-options="required:true,multiline:true" style="height: 60px;" class="form-control easyui-textbox" name="msgcontent"
                                   placeholder="消息内容" value="" aria-required="true">
                        </td>
                    </tr>

                    <tr>
                        <td>
                            <label class="col-sm-4 control-label">状态<span class="text-danger">*</span></label>
                        </td>
                        <td>
                            <select data-options="required:true" style="width: 171px" class="easyui-combobox" name="msgstate" placeholder="状态"
                                    aria-invalid="false">
                                <option value="0">草稿</option>
                                <option value="1" selected>发送</option>
                            </select>
                        </td>
                    </tr>

                    <tr>
                        <td>
                            <label class="col-sm-4 control-label">船舶<span class="text-danger">*</span></label>
                        </td>
                        <td>
                            <input class="easyui-combobox"
                                   name="shipid"
                                   data-options="
					              url:'<#if company??>/manage/ship/ajax/list<#else>/manage/ship/ajax/msaList</#if>',
					              method:'get',
					              required:true,
					              valueField:'shipid',
					              textField:'shipName',
					              editable:false,
					              multiple:true,
					              panelHeight:'auto'
			                     ">
                        </td>
                    </tr>
                </table>
            </form>

        </div>
        <div data-options="region:'south',border:false" style="text-align:right;padding:5px 0 0;">
            <a class="easyui-linkbutton" data-options="iconCls:'icon-ok'" href="javascript:void(0)" onclick="submitForm()" style="width:80px">提交</a>
            <a class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" href="javascript:void(0)" onclick="window.parent.layer.close(window.parent.sendLayer);" style="width:80px">取消</a>
        </div>
    </div>


<#--</div>-->

</body>
</html>